﻿<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<CallMVC.Models.LoginModel>" %>



<asp:Content ID="calcOutTitle" ContentPlaceHolderID="Title1" runat="server">

<%

      DBManager.Customer cust = ViewBag.Customer;
%>

   <a href="<%: Url.Action("Calculation", "Home", new { customerId = cust.CustomerID })%>"><img src="/CalcApp/images/<%= cust.LogoLink %>" /></a>
</asp:Content>

<asp:Content ID="calcOutContent" ContentPlaceHolderID="MainContent" runat="server">
    <%
        
        try
        {
            DBManager.DBManager.Instance.mutexlock();

         %>

<% 
    
  
    using (Html.BeginForm())
    { 
%>
    <%: Html.ValidationSummary()%>

<script language="javascript">

    $(document).ready(function () {
        //alert('Show Chart');
    });
</script>

    <ul data-role="listview" data-inset="true">
        <li data-role="fieldcontain"><h3><%: Html.Label(((DBManager.Calculation)this.ViewBag.Calculation).CaculationName)%></h3></li> 
    </ul>

<%
        if (ViewBag.IsGraphExist == true)
        {
%> 
    <ul data-role="listview" data-inset="true">
        <li data-role="fieldcontain">
            <div class="example-content">
                <img src="/CalcApp/Graph/<%=ViewBag.pictureName%>"  width="100%"/>
            </div>
        </li>
    </ul>
<%
        }
%>

<%
        int orderStatus = this.ViewBag.OrderStatus;
        if (orderStatus == 2)
        {             
         DBManager.Calculation calc = (DBManager.Calculation)this.ViewBag.Calculation;
        string myOrderId = (string)this.ViewBag.OrderId;

        foreach (DBManager.OutputDesignGroup group in calc.OutputDesignGroupsList)
        {
       
%>
    <ul data-role="listview" data-inset="true">
        <li data-role="fieldcontain">
            <div style="overflow:scroll" >
            <div>
                <b><%: Html.Label(group.grpName)%></b>
            </div>
            <table summary="This table lists all Input of Calculation">               

            <tbody>
<%   
            foreach (DBManager.OutputDesign outputDesign in group.outputDesignList)
            {
%>
                <tr>                   
<%
                //if (group.ColumnList.Count > 0 )                
                {
                    //foreach (DBManager.Column col in group.ColumnList)
                    
                    int count = 0;
                    int colNum = 0;
                    //print label
                    if (outputDesign.FirstColumn > 0)
                    {
                        if (count == 0)
                        {
                            string style = "text-align:left;";
                            
                            if (outputDesign.Bold == 1)
                            {
%>
                    <td style=" <%: style %> " >
                        <b>
                        <%: outputDesign.FieldDescription%> 
                        </b> 
                    </td>
<%                           
                                colNum = 1;
                            }
                            else
                            {
%>
                    <td style=" <%: style %> " >
                        <%: outputDesign.FieldDescription%> 
                    </td>
<%             
                                colNum = 1;
                            }
                            count++;                          
                        }
                    }
                    //no label
                    else
                    {
                        
                    }        
                    System.Collections.Generic.List<DBManager.OutputValue> outputValueList = DBManager.DBManager.Instance.GetOutputValuesList(calc.CalculationID, outputDesign.FieldID, myOrderId);
                    foreach (DBManager.OutputValue outputV in outputValueList)                    
                    {
                        //count until first column equal count and then print
                        //if (count < outputDesign.FirstColumn)
                        while (count < outputDesign.FirstColumn)                          
                        {                            
%>
                    <td>
                    </td>
<%                        
                            count++;
                            colNum++;            
                        }
                        //else
                        {
                            DBManager.OutputColumn outputCol = DBManager.DBManager.Instance.GetOutputColumn(outputV.CalculationID, outputV.FieldID, (int)outputV.ColumnNu);
                            
                            bool isNumber = false;

                            if (outputCol != null && outputCol.isNumber || outputDesign.FirstColumn == colNum && outputDesign.isNumber)
                                isNumber = true;
                                
                            
                            if (isNumber)
                            {
                                if (outputV.ColumnNu == colNum)
                                {

                                    string text_align = "right";

                                    if (outputV.Alignment == "L")
                                    {
                                        text_align = "left";
                                    }
                                    else
                                    {
                                        text_align = "right";
                                    }

%>
                    <td  style="text-align:<%=text_align%>;">
                    <%  if (outputDesign.Bold == 1)
                        { %>
                      <b>  <%: Html.Label(outputV.OutputValue1, outputV.OutputValue1)%>  </b>
                      
                      <% }
                        else
                        { %>
                      <%: Html.Label(outputV.OutputValue1, outputV.OutputValue1)%>

                      <% } %>                
                    </td>
<%   
                                    colNum++;
                                }
                            }
                            else
                            {
                                if (outputV.ColumnNu == colNum)
                                {

                                    string text_align = "right";

                                    if (outputV.Alignment == "L")
                                    {
                                        text_align = "left";
                                    }
                                    else
                                    {
                                        text_align = "right";
                                    }                                                                                                                              
%>
                    <td  style="text-align:<%=text_align%>;">
                    <%  if (outputDesign.Bold == 1)
                        { %>
                      <b>  <%: Html.Label(outputV.OutputValue1, outputV.OutputValue1)%>  </b>
                      
                      <% }
                        else
                        { %>
                      <%: Html.Label(outputV.OutputValue1, outputV.OutputValue1)%>

                      <% } %>            
                    </td>
<%                           
                                    colNum++;
                                }
                            }         
                        }
                        count++;                        
                    } 
                } 
%>                
                </tr>
<%
            }
%>
            </tbody> 
            </table> 
            </div>
        </li>
<% 
        }
        }
        else if (orderStatus == 6)
        {
%>            
    <li data-role="fieldcontain">
        <h2>Calculation timeout</h2>
    </li>  
<%            
        }           
%>      
    </ul>
<%
    }

    DBManager.DBManager.Instance.mutexUnlock();
%>

    <%


        }
        catch (Exception)
        {
            DBManager.DBManager.Instance.mutexUnlock();
            throw;
        }
    %>
    
</asp:Content>
